home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C & C++ Multimedia Cyber Classroom
/
C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso
/
cpphtp2
/
code.jar
/
code
/
ch14
/
fig14_04.txt
next >
Wrap
Text File
|
1998-02-27
|
917b
|
33 lines
1 // Fig. 14.4: fig14_04.cpp
2 // Create a sequential file
3 #include <iostream.h>
4 #include <fstream.h>
5 #include <stdlib.h>
6
7 int main()
8 {
9 // ofstream constructor opens file
10 ofstream outClientFile( "clients.dat", ios::out );
11
12 if ( !outClientFile ) { // overloaded ! operator
13 cerr << "File could not be opened" << endl;
14 exit( 1 ); // prototype in stdlib.h
15 }
16
17 cout << "Enter the account, name, and balance.\n"
18 << "Enter end-of-file to end input.\n? ";
19
20 int account;
21 char name[ 30 ];
22 float balance;
23
24 while ( cin >> account >> name >> balance ) {
25 outClientFile << account << ' ' << name
26 << ' ' << balance << '\n';
27 cout << "? ";
28 }
29
30 return 0; // ofstream destructor closes file
31 }